import store from "@/store/index.js"
import storage from "@/uni-sub-base/utils/storage.js"
import config from "@/config/config.js"
const appUrl = {
    //
    getShopUrls() {
        //TODO 待优化 改成不每次都取 storage
        let webInfo = storage.getCache("webInfo")
        let obj = {
            baseUrlShop: "",
            baseUrlChat: "",
            baseImgUrl: "",
            baseImgUrlShop: "",
        }
        if (webInfo) {
            let domain = webInfo.WebDomain
            obj = {
                baseUrlShop: domain + "/api/",
                baseUrlChat: webInfo.ChatDomain,
                baseImgUrl: webInfo.ImgDomain,
                baseImgUrlShop: domain,
            }
        }
        return obj
    },
    getUrlObj() {
        let urlObj
        //判断环境
        //TODO 待优化 改成不每次都取 storage
        let appService = storage.getCache("appService")
		let apiUrl = storage.getCache("apiUrl")
        if (!appService) {
            urlObj = config.useUrl
        } else {
            urlObj = appService == 1 ? config.releaseUrl : config.testUrl
        }
		if(apiUrl){
			// urlObj.baseUrl = apiUrl + "/"
			urlObj.baseUrl = apiUrl
		}
        // console.log("getUrlObj", urlObj)
        config.domain = urlObj.domain
        config.baseUrl = urlObj.baseUrl
        config.businessId = urlObj.businessId
        return urlObj
    },
    getBaseUrl() {
        return appUrl.getUrlObj().baseUrl
    },
    getDomain() {
        return appUrl.getUrlObj().domain
    },
	getBusinessld() {
	    return appUrl.getUrlObj().businessId
	},
}
module.exports = {
    getShopUrls: appUrl.getShopUrls,
    getBaseUrl: appUrl.getBaseUrl,
    getDomain: appUrl.getDomain,
    getBusinessld: appUrl.getBusinessld,
}
